package com.situ.student.listener;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.situ.student.entity.User;

public class MyHttpSessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent se) {
		
	}

	/**
	 * 30分钟不交互，就自动退出
	 */
	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		System.out.println("MyHttpSessionListener.sessionDestroyed()");
		HttpSession session = se.getSession();
		User user = (User) session.getAttribute("user");
		ServletContext servletContext = session.getServletContext();
		List<User> onLineUserList =  (List<User>) servletContext.getAttribute("onLineUserList");
		onLineUserList.remove(user);
		servletContext.setAttribute("onLineUserList", onLineUserList);
	}

}
